import {baseGet} from "./base";

function parseUrl(url) { //定义函数
  var pattern = /(\w+)=(\w+)/ig;//定义正则表达式
  var parames = {};//定义数组
  url.replace(pattern, function (a, b, c) {
    parames[b] = c;
  });
  return parames;//返回这个数组.
}

/*
* 验证手机号码
* */
function checkPhone(num) {
  let checkFun = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/
  if (checkFun.test(num)) {
    console.log('success');
    return num
  } else {
    wx.showToast({
      duration: 2000,
      title: '输入正确的手机号码',
      icon: 'none'
    })
    return null
  }
}

/*
* 正怎判断姓名只能是中英文
* */
function checkName(e) {
  let cn = /^[\u4e00-\u9fa5]|[a-zA-Z]$/
  if (cn.test(e)) {
    return e
  } else {
    return null
  }
}

function checkLogin() {
  wx.getStorage({
    key: 'userInfo',
    success(res) {
      console.log(res)
      let user = res.data
      return user
    },
    fail() {
      return 1
    }
  })
}

// 暴露api

module.exports = {
  parseUrl,
  checkName,
  checkLogin,
  checkPhone
}
